<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>微信小程序封装组件 | Jaho’s Blog</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/favicon.ico">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="记录日常学习工作">
    
    <link rel="preload" href="/assets/css/0.styles.5b8fe0a4.css" as="style"><link rel="preload" href="/assets/js/app.6514719e.js" as="script"><link rel="preload" href="/assets/js/2.ea114ffb.js" as="script"><link rel="preload" href="/assets/js/52.a9f595dc.js" as="script"><link rel="preload" href="/assets/js/4.e093c564.js" as="script"><link rel="prefetch" href="/assets/js/10.13203aa5.js"><link rel="prefetch" href="/assets/js/11.099868c4.js"><link rel="prefetch" href="/assets/js/12.c8365e17.js"><link rel="prefetch" href="/assets/js/13.89751e7c.js"><link rel="prefetch" href="/assets/js/14.31f563eb.js"><link rel="prefetch" href="/assets/js/15.08b381b6.js"><link rel="prefetch" href="/assets/js/16.1a3867de.js"><link rel="prefetch" href="/assets/js/17.7dd4e0c6.js"><link rel="prefetch" href="/assets/js/18.907c4597.js"><link rel="prefetch" href="/assets/js/19.fac8aa1a.js"><link rel="prefetch" href="/assets/js/20.73fe0e75.js"><link rel="prefetch" href="/assets/js/21.5c50aa1c.js"><link rel="prefetch" href="/assets/js/22.83d03663.js"><link rel="prefetch" href="/assets/js/23.061e7ac0.js"><link rel="prefetch" href="/assets/js/24.cc7e9011.js"><link rel="prefetch" href="/assets/js/25.fa6c7aef.js"><link rel="prefetch" href="/assets/js/26.39392f70.js"><link rel="prefetch" href="/assets/js/27.204436be.js"><link rel="prefetch" href="/assets/js/28.3f54c157.js"><link rel="prefetch" href="/assets/js/29.799d048c.js"><link rel="prefetch" href="/assets/js/3.6c5d6214.js"><link rel="prefetch" href="/assets/js/30.deed02f3.js"><link rel="prefetch" href="/assets/js/31.5916873b.js"><link rel="prefetch" href="/assets/js/32.b0634144.js"><link rel="prefetch" href="/assets/js/33.734675b8.js"><link rel="prefetch" href="/assets/js/34.20404dc4.js"><link rel="prefetch" href="/assets/js/35.d93b829f.js"><link rel="prefetch" href="/assets/js/36.b0692d8d.js"><link rel="prefetch" href="/assets/js/37.3dffa306.js"><link rel="prefetch" href="/assets/js/38.04649a97.js"><link rel="prefetch" href="/assets/js/39.7dfcdc32.js"><link rel="prefetch" href="/assets/js/40.04914511.js"><link rel="prefetch" href="/assets/js/41.ced85449.js"><link rel="prefetch" href="/assets/js/42.72739213.js"><link rel="prefetch" href="/assets/js/43.de1cff16.js"><link rel="prefetch" href="/assets/js/44.48e301ae.js"><link rel="prefetch" href="/assets/js/45.870a7650.js"><link rel="prefetch" href="/assets/js/46.657f15b8.js"><link rel="prefetch" href="/assets/js/47.3df1bfdb.js"><link rel="prefetch" href="/assets/js/48.f4e4e774.js"><link rel="prefetch" href="/assets/js/49.632bf611.js"><link rel="prefetch" href="/assets/js/5.6531e181.js"><link rel="prefetch" href="/assets/js/50.a8018493.js"><link rel="prefetch" href="/assets/js/51.cb424f59.js"><link rel="prefetch" href="/assets/js/53.cf8a9ec0.js"><link rel="prefetch" href="/assets/js/54.46d774a3.js"><link rel="prefetch" href="/assets/js/55.3574f9b8.js"><link rel="prefetch" href="/assets/js/56.baf60ba5.js"><link rel="prefetch" href="/assets/js/57.af42b559.js"><link rel="prefetch" href="/assets/js/58.9300cb59.js"><link rel="prefetch" href="/assets/js/6.00f437ec.js"><link rel="prefetch" href="/assets/js/7.58ac7166.js"><link rel="prefetch" href="/assets/js/8.1b9c5002.js"><link rel="prefetch" href="/assets/js/9.5c076362.js">
    <link rel="stylesheet" href="/assets/css/0.styles.5b8fe0a4.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="Jaho’s Blog" class="logo"> <span class="site-name can-hide">Jaho’s Blog</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/posts/" class="nav-link router-link-active">
  技术博客
</a></div> <a href="https://juejin.cn/user/26836627369806" target="_blank" rel="noopener noreferrer" class="repo-link">
    个人主页
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><a href="/posts/" aria-current="page" class="sidebar-link">写在前面</a></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>工作问题解决</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/posts/项目问题解决/vuevite.html" class="sidebar-link">vue3+vite用proxy解决跨域及proxy原理解析</a></li><li><a href="/posts/项目问题解决/大文件.html" class="sidebar-link">大文件切片上传和断点续传</a></li><li><a href="/posts/项目问题解决/代码优化.html" class="sidebar-link">实际工作中代码优化</a></li><li><a href="/posts/项目问题解决/组件问题.html" class="sidebar-link">解决组件传值问题</a></li><li><a href="/posts/项目问题解决/动态组件.html" class="sidebar-link">动态组件实践</a></li><li><a href="/posts/项目问题解决/大屏.html" class="sidebar-link">大屏九宫格视频</a></li><li><a href="/posts/项目问题解决/滚动.html" class="sidebar-link">Vue中Element表单定位滚动到校验错误位置</a></li><li><a href="/posts/项目问题解决/红绿灯.html" class="sidebar-link">Promise实现动态红绿灯切换</a></li><li><a href="/posts/项目问题解决/懒加载.html" class="sidebar-link">实现元素懒加载</a></li><li><a href="/posts/项目问题解决/小程序组件.html" class="active sidebar-link">微信小程序封装组件</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/posts/项目问题解决/axios.html" class="sidebar-link">项目中对axios的整体封装</a></li><li><a href="/posts/项目问题解决/docker.html" class="sidebar-link">docker实践(附windows安装下载教程)</a></li><li><a href="/posts/项目问题解决/eltable.html" class="sidebar-link">el-table自定义表头及无数据状态</a></li><li><a href="/posts/项目问题解决/gojs.html" class="sidebar-link">gojs入门学习</a></li><li><a href="/posts/项目问题解决/react踩坑.html" class="sidebar-link">React踩坑</a></li><li><a href="/posts/项目问题解决/小程序踩坑.html" class="sidebar-link">小程序踩坑</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Css</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Nodejs</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Git</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="微信小程序封装组件"><a href="#微信小程序封装组件" class="header-anchor">#</a> 微信小程序封装组件</h1> <blockquote><p>需求出现了对小程序项目弹框进行自定义按钮和标题的自定义，于是直接封装成可复用的组件，效果如图：
<img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f563d508e4fd4baea309ab42d77e1f90~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p></blockquote> <h3 id="组件代码-logs-wxml"><a href="#组件代码-logs-wxml" class="header-anchor">#</a> 组件代码 logs.wxml</h3> <div class="language- extra-class"><pre class="language-text"><code>&lt;!--logs.wxml--&gt;
&lt;view class=&quot;model_mask&quot; hidden=&quot;{{!isShow}}&quot;&gt;&lt;/view&gt;
&lt;view class=&quot;model_content&quot; hidden=&quot;{{!isShow}}&quot;&gt;
  &lt;!-- 插槽 --&gt;
  &lt;view class=&quot;model_title&quot;&gt;{{titleText}}&lt;/view&gt;
  &lt;view class=&quot;model_main&quot;&gt; 
    &lt;slot class=&quot;slotSty&quot;&gt;&lt;/slot&gt;
  &lt;/view&gt;
  &lt;view class=&quot;model_btm&quot;&gt;
    &lt;!-- catchtap监听到点击-&gt;触发自身的bindeConfirm事件 --&gt;
    &lt;view hidden=&quot;{{!showConfirm}}&quot; catchtap=&quot;bindConfirm&quot; style=&quot;color: {{showConfirmColor}};&quot;  &gt;{{confirmText}}&lt;/view&gt;
    &lt;view hidden=&quot;{{!showCancel}}&quot; catchtap=&quot;bindCancel&quot; style=&quot;color: {{showCancelColor}};&quot;&gt;{{cancelText}}&lt;/view&gt;
  &lt;/view&gt; 
&lt;/view&gt;    
</code></pre></div><h3 id="logs-wxss"><a href="#logs-wxss" class="header-anchor">#</a> logs.wxss</h3> <div class="language-js extra-class"><pre class="language-js"><code><span class="token punctuation">.</span>model_mask<span class="token punctuation">{</span>
  <span class="token literal-property property">position</span><span class="token operator">:</span> fixed<span class="token punctuation">;</span>
  <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">right</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">bottom</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">background</span><span class="token operator">:</span> #<span class="token number">000</span><span class="token punctuation">;</span>
  <span class="token literal-property property">opacity</span><span class="token operator">:</span> <span class="token number">0.5</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">.</span>model_content<span class="token punctuation">{</span> 
  <span class="token literal-property property">position</span><span class="token operator">:</span> absolute<span class="token punctuation">;</span>
  <span class="token literal-property property">top</span><span class="token operator">:</span> <span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">;</span>
  <span class="token literal-property property">left</span><span class="token operator">:</span> <span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">;</span>
  <span class="token literal-property property">width</span><span class="token operator">:</span> 600rpx<span class="token punctuation">;</span>
  <span class="token literal-property property">height</span><span class="token operator">:</span> 600rpx<span class="token punctuation">;</span>
  <span class="token literal-property property">background</span><span class="token operator">:</span> #fff<span class="token punctuation">;</span>
  border<span class="token operator">-</span>radius<span class="token operator">:</span> 16rpx<span class="token punctuation">;</span>
  <span class="token literal-property property">transform</span><span class="token operator">:</span> <span class="token function">translate</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">50</span><span class="token operator">%</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">.</span>model_title<span class="token punctuation">{</span>
  text<span class="token operator">-</span>align<span class="token operator">:</span> center<span class="token punctuation">;</span>
  <span class="token literal-property property">color</span><span class="token operator">:</span> gray<span class="token punctuation">;</span>
  <span class="token literal-property property">padding</span><span class="token operator">:</span> 20rpx <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">.</span>model_btm<span class="token punctuation">{</span>
  <span class="token literal-property property">position</span><span class="token operator">:</span> absolute<span class="token punctuation">;</span>
  <span class="token literal-property property">bottom</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  text<span class="token operator">-</span>align<span class="token operator">:</span> center<span class="token punctuation">;</span>
  <span class="token literal-property property">width</span><span class="token operator">:</span> <span class="token number">100</span><span class="token operator">%</span><span class="token punctuation">;</span>
  <span class="token literal-property property">display</span><span class="token operator">:</span> flex<span class="token punctuation">;</span>
  <span class="token literal-property property">height</span><span class="token operator">:</span> 96rpx<span class="token punctuation">;</span>
  line<span class="token operator">-</span>height<span class="token operator">:</span> 96rpx<span class="token punctuation">;</span>
  border<span class="token operator">-</span>top<span class="token operator">:</span> 2rpx solid #<span class="token constant">F1F1F1</span><span class="token punctuation">;</span>
  text<span class="token operator">-</span>align<span class="token operator">:</span> center<span class="token punctuation">;</span>
  font<span class="token operator">-</span>size<span class="token operator">:</span> 32rpx<span class="token punctuation">;</span>
  font<span class="token operator">-</span>family<span class="token operator">:</span> PingFangSC<span class="token operator">-</span>Medium<span class="token punctuation">,</span> PingFang <span class="token constant">SC</span><span class="token punctuation">;</span>
  font<span class="token operator">-</span>weight<span class="token operator">:</span> <span class="token number">500</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">.</span>model_btm view<span class="token punctuation">{</span>
  <span class="token literal-property property">flex</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span> 
<span class="token punctuation">.</span>model_main<span class="token punctuation">{</span>
  <span class="token literal-property property">padding</span><span class="token operator">:</span> 35rpx<span class="token punctuation">;</span>
  line<span class="token operator">-</span>height<span class="token operator">:</span> 48rpx<span class="token punctuation">;</span>
  font<span class="token operator">-</span>size<span class="token operator">:</span> 28rpx<span class="token punctuation">;</span>
  <span class="token literal-property property">padding</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">margin</span><span class="token operator">:</span> 8rpx 16rpx <span class="token number">0</span><span class="token punctuation">;</span>
  <span class="token literal-property property">color</span><span class="token operator">:</span> #1F2329<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="logs-js"><a href="#logs-js" class="header-anchor">#</a> logs.js</h3> <div class="language-js extra-class"><pre class="language-js"><code><span class="token function">Component</span><span class="token punctuation">(</span><span class="token punctuation">{</span>

  <span class="token literal-property property">behaviors</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>

  <span class="token comment">// 属性定义（详情参见下文）</span>
  <span class="token literal-property property">properties</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token literal-property property">isShow</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">//控制整个蒙版显示</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span> Boolean<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">confirmText</span><span class="token operator">:</span><span class="token punctuation">{</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span>String<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span><span class="token string">'确认'</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">cancelText</span><span class="token operator">:</span><span class="token punctuation">{</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span>String<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span><span class="token string">'取消'</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">titleText</span><span class="token operator">:</span><span class="token punctuation">{</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span>String<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span><span class="token string">'提示'</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">showConfirm</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token comment">//控制确定按钮显示</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span>Boolean<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span><span class="token boolean">true</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">showCancel</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token comment">//控制取消按钮显示</span>
      <span class="token literal-property property">type</span><span class="token operator">:</span>Boolean<span class="token punctuation">,</span>
      <span class="token literal-property property">value</span><span class="token operator">:</span><span class="token boolean">true</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">showConfirmColor</span><span class="token operator">:</span><span class="token string">'black'</span><span class="token punctuation">,</span>
    <span class="token literal-property property">showCancelColor</span><span class="token operator">:</span><span class="token string">'black'</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token literal-property property">methods</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token function-variable function">bindConfirm</span><span class="token operator">:</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment">//点击确认按钮&lt;1.触发实例确认事件&gt;并&lt;2.隐藏弹框&gt;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">triggerEvent</span><span class="token punctuation">(</span><span class="token string">'confirm'</span> <span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//触发实例上监听的事件confirm，在index.js中的事件</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setData</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        <span class="token literal-property property">isShow</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function-variable function">bindCancel</span><span class="token operator">:</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment">//点击取消按钮&lt;1.触发实例取消事件&gt;并&lt;2.隐藏弹框&gt;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">triggerEvent</span><span class="token punctuation">(</span><span class="token string">'cancel'</span> <span class="token punctuation">,</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setData</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        <span class="token literal-property property">isShow</span><span class="token operator">:</span><span class="token boolean">false</span><span class="token punctuation">,</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><blockquote><p>组件空框架显示如图，通过引入组件传值实现各种标题样式和按钮样式的显示控制，
同时中间通过slot进行插槽传值信息</p></blockquote> <p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1b18ef30b0f3424894584da544d280c6~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
以上就是整个封装的弹框组件代码，接下来在页面中当成组件在index.json进行引入</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token punctuation">{</span>
  <span class="token string-property property">&quot;usingComponents&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token string-property property">&quot;component&quot;</span><span class="token operator">:</span><span class="token string">&quot;/pages/logs/logs&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="index-wxml"><a href="#index-wxml" class="header-anchor">#</a> index.wxml</h3> <div class="language- extra-class"><pre class="language-text"><code>&lt;component
  showConfirm=&quot;{{true}}&quot; 
  showCancel=&quot;{{true}}&quot;
  titleText=&quot;提示内容&quot;
  cancelText=&quot;再想想&quot;  
  confirmText=&quot;确定下单&quot;
  showCancelColor=&quot;#1F2329&quot;
  showConfirmColor=&quot;#58B392&quot;
  bind:cancel=&quot;toCancel&quot;
  bind:confirm=&quot;toConfirm&quot;
&gt;
&lt;view&gt;1、如已报名该项管服务，退款后仍可能需要补缴费用，具体请以学校通知为准&lt;/view&gt; 
&lt;/component&gt;  
</code></pre></div><h3 id="index-js"><a href="#index-js" class="header-anchor">#</a> index.js</h3> <div class="language- extra-class"><pre class="language-text"><code>// 获取应用实例
const app = getApp()
Page({
  data: {
    showConfirm:false,//控制确定按钮显示
    showCancel:false,//控制取消按钮显示
  },
  toConfirm(){
    console.log(111)
  },
  toCancel(){
    console.log(222)
  }
</code></pre></div><blockquote><p>在页面中应用显示效果</p></blockquote> <p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f0e7529f69384ffcbcc9bde982f44586~tplv-k3u1fbpfcp-watermark.image?" alt="image.png"></p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023-01-04 10:56:12</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/posts/项目问题解决/懒加载.html" class="prev">
        实现元素懒加载
      </a></span> <span class="next"><a href="/posts/项目问题解决/axios.html">
        项目中对axios的整体封装
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><!----></div></div>
    <script src="/assets/js/app.6514719e.js" defer></script><script src="/assets/js/2.ea114ffb.js" defer></script><script src="/assets/js/52.a9f595dc.js" defer></script><script src="/assets/js/4.e093c564.js" defer></script>
  </body>
</html>
